package Review;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Wukong
 * Date: 2022-06-04
 * Time: 16:24
 */
class Money implements Cloneable{
    protected double money=20.2;

    @Override
    protected Object clone() throws CloneNotSupportedException {
        return super.clone();
    }
}
public class Person implements Cloneable{
    public int age=20;
    Money money=new Money();

    @Override
    public Object clone() throws CloneNotSupportedException {
     Person person=(Person) super.clone();
     person.money=(Money) this.money.clone();
     return person;

    }

    public static void main(String[] args) throws CloneNotSupportedException {
        Person person=new Person();
        Person person2=(Person)person.clone();

        person2.age=21;
        System.out.println(person.age);
        System.out.println(person2.age);
        //深浅拷贝
        person2.money.money=20.1;

        System.out.println(person.money.money);//20.2
        System.out.println( person2.money.money);//20.2



    }
}
